package Jets.shapes
{
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.geom.Point;
	
	public class JAnglePolygon extends Shape
	{
		private var ms_nSize:int = 50;
		private var ms_nLineColor:int = 0x0;
		private var ms_nLineThins:int = 1;
		private var ms_nInColor:int = 0xFF;
		private var ms_nVertex:int = 6;
		private var ms_nPointSize:Number =0.5;
		private var ms_nPtArr:Array;
		private var ms_nRo:Number;
		
		/**
		 * 画多个角的图形
		 * @param size:图像的大小
		 * @param vertex:角顶点 
		 * @param vertexSize:临界点相对大小，根据size乘以此参数得出
		 * @param fillColor:填充的颜色
		 * @param line:边线的宽度 ，宽度为0时，不画边线
		 * @param lineColor:边线的颜色
		 * 画五角星时 可以使用 vertex=5 ，vertexSize=0.5
		 */
		public function JAnglePolygon(size = 50,vertex:int=5,vertexSize:Number=0.5,fillColor:int=0xFF0000,line:int=1,lineColor:int=0) 
		{
			ms_nSize = size;
			ms_nVertex = vertex;
			ms_nPointSize = vertexSize;
			ms_nInColor = fillColor;
			ms_nLineThins = line;
			ms_nLineColor = lineColor;
			if (ms_nVertex%2==0) 
			{
				ms_nRo=0;
			} 
			else 
			{
				ms_nRo = Math.PI/(ms_nVertex*2);
			}
			drawPolygon();
		}
		
		private function drawPolygon():void 
		{
			ms_nPtArr = new Array();
			for (var i:uint=0; i<ms_nVertex; i++) 
			{
				var p:Point = new Point();
				var vertexDegree:Number = 360/ms_nVertex*i*Math.PI/180 - ms_nRo ;
				p=Point.polar(ms_nSize,vertexDegree);
				ms_nPtArr.push(p);
				
				var p2:Point = new Point();
				var innerDegree:Number = 360/ms_nVertex*(i+.5)*Math.PI/180 - ms_nRo;
				p2=Point.polar(ms_nSize*ms_nPointSize,innerDegree);
				ms_nPtArr.push(p2);
			}
			
			this.graphics.clear();
			if(ms_nLineThins)
			{
				this.graphics.lineStyle(ms_nLineThins,ms_nLineColor);
			}
			this.graphics.beginFill(ms_nInColor);
			this.graphics.moveTo(ms_nPtArr[0].x,ms_nPtArr[0].y);
			for (i=1; i<ms_nPtArr.length; i++) 
			{
				this.graphics.lineTo(ms_nPtArr[i].x,ms_nPtArr[i].y);
			}
			this.graphics.lineTo(ms_nPtArr[0].x,ms_nPtArr[0].y);
			this.graphics.endFill();
		}
		
		/**
		 * 画多个角的图形
		 * @param size:图像的大小
		 * @param vertex:角顶点 
		 * @param vertexSize:临界点相对大小，根据size乘以此参数得出
		 * @param fillColor:填充的颜色
		 * @param line:边线的宽度 ，宽度为0时，不画边线
		 * @param lineColor:边线的颜色
		 * 画五角星时 可以使用 vertex=5 ，vertexSize=0.5
		 */
		static public function DrawAnglePolygon(g:Graphics,size = 50,vertex:int=5,vertexSize:Number=0.5,fillColor:int=0xFF0000,line:int=1,lineColor:int=0,isClear:Boolean=false):void
		{
			var ptArr:Array = new Array();
			var ro:Number;
			if (vertex%2==0) 
			{
				ro=0;
			} 
			else 
			{
				ro = Math.PI/(vertex*2);
			}
			for (var i:uint=0; i<vertex; i++) 
			{
				var p:Point = new Point();
				var vertexDegree:Number = 360/vertex*i*Math.PI/180 - ro ;
				p=Point.polar(size,vertexDegree);
				ptArr.push(p);
				
				var p2:Point = new Point();
				var innerDegree:Number = 360/vertex*(i+.5)*Math.PI/180 - ro;
				p2=Point.polar(size*vertexSize,innerDegree);
				ptArr.push(p2);
			}
			if(isClear)
			{
				g.clear();
			}
			if(line)
			{
				g.lineStyle(line,lineColor);
			}
			g.beginFill(fillColor);
			g.moveTo(ptArr[0].x,ptArr[0].y);
			for (i=1; i<ptArr.length; i++) 
			{
				g.lineTo(ptArr[i].x,ptArr[i].y);
			}
			g.lineTo(ptArr[0].x,ptArr[0].y);
			g.endFill();
		}
	}
}

